package com.edgclub.edg.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.edgclub.edg.R;
import com.edgclub.edg.fragment.OtherUserBBFragment;
import com.edgclub.edg.model.User;

import java.util.ArrayList;


public class UserInfoActionActivity extends GzBaseTooolBarActivity implements View.OnClickListener{

    private ViewPager mViewpager2;
    private MyPagerAdapter myPagerAdapter;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();;
    private String titlestr="";
    @Override
    public int getContentView() {
        return R.layout.activity_action1;
    }

    @Override
    public void setTitleBarView() {
        setCustomActionBar();
        titlestr=getIntent().getStringExtra("title")+"";
        title.setText(titlestr);
        main_back.setVisibility(View.VISIBLE);
        main_back.setOnClickListener(this);
    }

    @Override
    public void initView() {
        mViewpager2 = (ViewPager) findViewById(R.id.viewpager2);
    }

    @Override
    public void initData() {
        User user= (User) getIntent().getSerializableExtra("user");
        myPagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
        if("我的贴子".equals(titlestr)){
            fragmentList.add(OtherUserBBFragment.newInstance(user,0));
        }else{
            fragmentList.add(OtherUserBBFragment.newInstance(user,1));
        }
        myPagerAdapter.setFragmentList(fragmentList);
        mViewpager2.setAdapter(myPagerAdapter);
        mViewpager2.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.main_back:
                finish();
                break;

        }
        }
        public class MyPagerAdapter extends FragmentPagerAdapter {

            ArrayList<Fragment> fragmentList;

            public MyPagerAdapter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return "";
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }


            public void setFragmentList(ArrayList<Fragment> fragmentList) {
                this.fragmentList = fragmentList;
            }
        }
}
